import { createApp, onUnmounted } from "vue";
import MessageIndex from "../components/MessageIndex.vue";
export type messageType = "success" | "error" | "default";
// 创建实例
//第一个参数是根节点  
//第二个参数是传给根节点组件的props 是可选的
const createMessage = (message: string, type: messageType, timeout= 2000) => {
  // 创建实例
  const messageInstance = createApp(MessageIndex, { message, type });
  //创建节点
  const mountNode = document.createElement("div");

  //挂载节点
  document.body.appendChild(mountNode);
  mountNode.id='message'
  //挂载组件
  messageInstance.mount(mountNode);
  setTimeout(() => {
    messageInstance.unmount(); //卸载组件
    document.body.removeChild(mountNode); //删除节
  }, timeout);
};
export default createMessage;
